package com.me.darkness_is_coming.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.StretchViewport;
import com.me.darkness_is_coming.actors.MenuButton;
import com.me.darkness_is_coming.main.MainGame;

public class MenuScreen implements Screen
{
	private Texture background_image;
	private SpriteBatch batch;
	private Stage stage;
	private MenuButton playButton;
	private MenuButton scoreButton;
    private MenuButton rulesButton;

	public MenuScreen(SpriteBatch batch)
	{
		this.batch = batch;
		background_image = new Texture("data/Fons/MenuFon.png");
		playButton = new MenuButton(new Texture("data/Menu/MenuButtonPlay.png"), MenuButton.PLAY, Gdx.graphics.getWidth()*0.238f, Gdx.graphics.getHeight()*0.609f, Gdx.graphics.getWidth()*0.523f, Gdx.graphics.getWidth()*0.083f);
		scoreButton = new MenuButton(new Texture("data/Menu/MenuButtonScore.png"), MenuButton.SCORE, Gdx.graphics.getWidth()*0.238f, Gdx.graphics.getHeight()*0.515f, Gdx.graphics.getWidth()*0.523f, Gdx.graphics.getWidth()*0.083f);
        rulesButton = new MenuButton(new Texture("data/Menu/MenuButtonRules.png"), MenuButton.RULES, Gdx.graphics.getWidth()*0.238f, Gdx.graphics.getHeight()*0.42f, Gdx.graphics.getWidth()*0.523f, Gdx.graphics.getWidth()*0.083f);
        playButton.clearListeners();
        playButton.addListener(new InputListener()
        {
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
            {
                MainGame.getInstance().newGame();
                return false;
            }

            public void touchUp (InputEvent event, float x, float y, int pointer, int button)
            {
            }
        });

        stage = new Stage(new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
        stage.addActor(playButton);
		stage.addActor(scoreButton);
        stage.addActor(rulesButton);
	}

	@Override
	public void render(float delta)
	{
		Gdx.gl.glClearColor(27f/255f, 196f/255f, 245f/255f, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		batch.begin();
		batch.draw(background_image, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		batch.end();
		stage.act(delta);
		stage.draw();
	}

	@Override
	public void resize(int width, int height)
	{
        stage.getViewport().update(width, height, false);
	}
	@Override
	public void show()
	{
		Gdx.input.setInputProcessor(stage);
	}
	@Override
	public void hide()
	{
		//
	}
	@Override
	public void pause()
	{
		//
	}
	@Override
	public void resume()
	{
		//
	}
	@Override
	public void dispose()
	{
        stage.dispose();
        background_image.dispose();
        playButton.dispose();
        scoreButton.dispose();
        rulesButton.dispose();
	}
}
